package com.hy.controller;

import com.hy.common.Result;
import com.hy.entity.Weekly;
import com.hy.service.WeeklyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/weeklies")
public class WeeklyController {

    @Autowired
    private WeeklyService weeklyService;

    @GetMapping
    public Result<List<Weekly>> getAllWeeklies() {
        return Result.success(weeklyService.list());
    }

    @PostMapping("/likeWeekly")
    public Result<Void> likeWeekly(@RequestBody Weekly weekly) {
        return weeklyService.likeWeekly(weekly);
    }

    @GetMapping("/{id}")
    public Result<Weekly> getWeekly(@PathVariable Long id) {
        return Result.success(weeklyService.getById(id));
    }

    @PostMapping
    public Result<Boolean> addWeekly(@RequestBody Weekly weekly) {
        return Result.success(weeklyService.save(weekly));
    }

    @PutMapping("/{id}")
    public Result<Boolean> updateWeekly(@PathVariable Integer id, @RequestBody Weekly weekly) {
        weekly.setId(id);
        return Result.success(weeklyService.updateById(weekly));
    }

    @DeleteMapping("/{id}")
    public Result<Boolean> deleteWeekly(@PathVariable Long id) {
        return Result.success(weeklyService.removeById(id));
    }
} 